
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytools;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**

 *

 * @author xiaoxiao

 */
public class loginAction extends ActionSupport {

    private String username;
    private String password;
    private String tip;

    public loginAction() {
    }

    public String execute() throws Exception {

        user user = new user();
        user.setUsername(getUsername());
        user.setPassword(getPassword());
        userDAO ud = new userDAO();
        int i = ud.login(user);
        boolean islogin=false;
        if (i == 1) {
            user u = new user();
            u = ud.getlogininfo(user);
            ActionContext actioncontext = ActionContext.getContext();
            actioncontext.getSession().put("username", username);
            actioncontext.getSession().put("password", password);
            actioncontext.getSession().put("email", u.getEmail());
            actioncontext.getSession().put("userid", u.getUserid());
            actioncontext.getSession().put("qx", u.getQx());
            actioncontext.getSession().put("islogin", true);
            return SUCCESS;
        } else {
            this.setTip(this.getText("login.failed"));
            return INPUT;
        }
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the tip
     */
    public String getTip() {
        return tip;
    }

    /**
     * @param tip the tip to set
     */
    public void setTip(String tip) {
        this.tip = tip;
    }
}
